Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graceful termination #49

Closed
wants to merge 55 commits into from

Conversation

stephenc-pace
Copy link
Collaborator

@stephenc-pace stephenc-pace commented Nov 25, 2022

Summary

Http2 supports the concept of a GOAWAY frame
https://www.rfc-editor.org/rfc/rfc7540#section-6.8
which our underlying library (h2) doesn't handle correctly (python-hyper/h2#1181)

This is an attempt to patch in support to h2 and then handle it more correctly from our side.

Copy link
Member

@mattbennett mattbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see progress on this problem finally!

How did you figure out that the GOAWAY handling was causing the problem?

@@ -142,7 +168,9 @@ def run_forever(self):
self.connection_terminated(event)

def stop(self):
self.run = False
self.conn.close_connection()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -199,6 +238,7 @@ def window_updated(self, event):
Any data waiting to be sent on the stream may fit in the window now.
"""
log.debug("window updated, stream %s", event.stream_id)
self.send_headers(event.stream_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this a pre-existing bug that you've happened to identify as part of this work? If so, how did you identity it?

@@ -269,6 +322,10 @@ def send_data(self, stream_id):
# has been completely sent
return

# No headers are present on close so send streams fail to exhaust without
# a manual call to flush the queue (will either be an error or END_STREAM stuck)
send_stream.flush_queue_to_buffer()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find. Can you add a regression test case for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will have a look. It came up through existing tests so I'll work out which ones cover it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not easily. I added it as the tests were timing out (hanging) without it but removing it now and they appear to be passing still. I think it still makes sense to have it but it's tricky to test specifically.

nameko_grpc/connection.py Show resolved Hide resolved
nameko_grpc/connection.py Outdated Show resolved Hide resolved
@stephenc-pace
Copy link
Collaborator Author

Great to see progress on this problem finally!

How did you figure out that the GOAWAY handling was causing the problem?

We had a service in QA that was conveniently exhitibing the error continuously so I was able to use the Nameko backdoor and monkey-patch in logging with it running.

(I had planned on using Rookout as suggested but the Nameko backdoor was already available (and Python's nice enough to patch running code 😂 )

nameko_grpc/streams.py Outdated Show resolved Hide resolved
@stephenc-pace
Copy link
Collaborator Author

This needs cleaning up as it has a few fixes on it now. I might have to recreate it.

@stephenc-pace
Copy link
Collaborator Author

Refactoring to exclude other fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants